package cn.wang.web.cargo.packing;


import cn.wang.entity.cargo.export.Export;
import cn.wang.entity.cargo.packing.PackingList;
import cn.wang.service.cargo.export.ExportService;
import cn.wang.service.cargo.packing.PackingListService;
import cn.wang.utils.Pagination;
import cn.wang.web.BaseAction;
import com.opensymphony.xwork2.ModelDriven;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * extCproductAction
 * Created by john on 2017/11/1.
 */
@Controller
public class PackingListAction extends BaseAction implements ModelDriven<PackingList> {
    private Pagination page = new Pagination();
    private List<PackingList> packingListList;
    private List<Export> exportList;
    private PackingList model = new PackingList();
    @Autowired
    private PackingListService packingListService;
    @Autowired
    private ExportService exportService;

    //装箱单显示 分页(statewei  0)
    public String list() {
        page = packingListService.findPage(page.getPageNo(), page.getPageSize(),0l);
        page.setUrl("packingListAction_list");
        push(page);
        return "list";
    }

    //添加装箱单前 查询所有已提交的报运单数据数据 state=1
    public String tocreate() {
        page = exportService.findPage(page.getPageNo(), page.getPageSize(), 1);
        page.setUrl("packingListAction_tocreate");
        push(page);
        return "tocreate";
    }

    //查询装箱单信息
    public String toview() {
        model = packingListService.findById(model.getId());
        push(model);
        return "toview";
    }

    //添加装箱单
    public String insert() {
        //保存装箱单 修改报运运单状态为2
        //设置状态为0 草稿
        packingListService.save(model);
        return "rlist";
    }

    //更新合同 先查询老数据
    public String toupdate() {
        //根据id查询老shuju1
        model = packingListService.findById(model.getId());
        push(model);
        return "toupdate";
    }

    public String update() {
        packingListService.update(model);
        return "rlist";
    }

    //删除部门 多个部门删除时 id 字符类型id会 拼接在一起(,空格)
    public String delete() {
        if (model.getId() == null) {
            return "rlist";
        }
        String[] ids = model.getId().split(", ");
        packingListService.delete(ids);
        return "rlist";
    }
    //提交将状态设置为 1
    public String submit(){
        if (model.getId() == null) {
            return "rlist";
        }
        String[] ids = model.getId().split(", ");
        packingListService.submit(ids);
        return "rlist";

    }

    public void setPage(Pagination page) {
        this.page = page;
    }

    public List<PackingList> getPackingListList() {
        return packingListList;
    }

    @Override
    public PackingList getModel() {
        //将字段名设为model使一行代码两用 1模型驱动 2 字段set方法
        return model;
    }
}
